﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using 简单三层架构.BLL;
using 简单三层架构.Model;

namespace 简单三层架构.Controls
{
    public partial class ItemList : System.Web.UI.UserControl
    {
        public string Keyword { get; set; }
        public string CategoryId { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public void DataBind()
        {
            Item bllItem = new Item();

            if (Keyword != null)
            {
                lvwItems.DataSource = bllItem.GetItemsBySearch(Keyword);
            }
            else if (CategoryId != null)
            {
                lvwItems.DataSource = bllItem.GetItemsByCategory(Convert.ToInt32(CategoryId));
            }
            else
            {
                lvwItems.DataSource = bllItem.GetAllItems();
            }

            lvwItems.DataBind();
        }

        protected void lvwItems_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "buy")
            {
                Response.Redirect("Buy.aspx?itemid=" + e.CommandArgument);
            }
        }
    }
}